﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Web;
using AGRTraining.za.co.agrtraining.model;
using AGRTraining.za.co.agrtraining.repository.Impl;

namespace AGRTraining.za.co.agrtraining.services.impl
{
    public class CourseServiceImpl:ICourseService
    {
        private AGRModelContainer agrDb = new AGRModelContainer();
        private CourseDAO courseDao = new CourseDAO();

        public IEnumerable<Student> viewAllStudentsInCourse(string courseCode)
        {
            var studs = from crs in agrDb.Courses
                        from factStudCourse in agrDb.FactStudentCourses
                        from stud in agrDb.Students
                        where crs.CourseCode == courseCode
                        where crs.CourseCode == factStudCourse.CourseCode
                        where factStudCourse.StudentCode == stud.StudentCode
                        select stud;
            IEnumerable<Student> students = new List<Student>();
            students = studs;
            return students;
        }
        public void addNewCourse(Hashtable crse)
        {
            Course course = new Course();
            course.CourseName =(string)crse["courseName"];
            course.CourseDuration = (string)crse["courseDur"];
            course.CourseCategory = (string)crse["courseCat"];
            course.CourseAccreditationNumber = (string)crse["courseAccreditNum"];
            courseDao.merge(course);
            courseDao.commit();
        }
    }
}